<?php

/**
 * Created by JetBrains PhpStorm.
 * User: Grom Hellscream
 * Date: 11/2/12
 * Time: 1:19 PM
 * To change this template use File | Settings | File Templates.
 */
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// Include dependancy of the main model form
jimport('joomla.application.component.modelform');
// import Joomla modelitem library
jimport('joomla.application.component.modelitem');
// Include dependancy of the dispatcher
jimport('joomla.event.dispatcher');

/**
 * Baocao Model
 */
class VastModelBaocao extends JModelForm {

    public function getForm($data = array(), $loadData = true) {
        // Get the form.
        $form = $this->loadForm('com_vast.baocao', 'baocao', array('control' => 'jform', 'load_data' => true));
        if (empty($form)) {
            return false;
        }
        
        return $form;
    }
     
    public function getVeHuu()
    {
        $tuoiNam = JRequest::getInt('nam', 60);
        $tuoiNu = JRequest::getInt('nu', 55);
        
        $db = JFactory::getDBO();
        $query = $db->getQuery(true);

        $query->select('a.*');
        $query->from('#__hosocanbo AS a');
        $query->where('(DATEDIFF(CURDATE(), `ngaysinh`)/365 >= ' . $tuoiNu . ' AND `gioitinh` = 0) OR (DATEDIFF(CURDATE(), `ngaysinh`)/365 >= ' . $tuoiNam . ' AND `gioitinh` = 1)');
        
        $db->setQuery($query);
        
        return $db->loadObjectList();        
    }        
}